package org.ade.monak.anak.service.gate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MultiSMSReceiver {

	
	public boolean isDone(){
		if(length>0){
			for(int i=0;i<length;i++){
				boolean ada = false;
				for(int index:listIndex){
					if(i==index){
						ada = true;
						break;
					}
				}
				if(!ada){
					return false;
				}
			}
			return true;
		}
		return false;
	}
	
	public String getPesan(){
		if(isDone()){
			String pesan = "";
			for(int i=0;i<length;i++){
				pesan+=mapPesan.get(i);
			}
			return pesan;
		}
		return "";
	}
	
	public void addPesan(String pesan){
		String [] splitPesan = pesan.split("#");
		
		if(splitPesan.length>3){
			int 	index 		= Integer.parseInt(splitPesan[1]);
			String 	textPesan 	= splitPesan[2];
			
			listIndex.add(index);
			mapPesan.put(index, textPesan);
			
			// dapet length pesan.................
			if(splitPesan[3].equals("Y")){
				length = index+1;
			}
			//....................................	
		}
			
	}
	
	private int 					length		= 0;				
	private List<Integer> 			listIndex 	= new  ArrayList<Integer>();
	private Map<Integer, String> 	mapPesan 	= new HashMap<Integer, String>();  
}
